import tensorflow.keras as keras
from tensorflow.keras import layers
from tensorflow.keras.datasets import mnist


# defined training params
batch_size = 1000
num_classes = 10
epochs = 10

# the data, split between train and test sets
(x_train,y_train),(x_test,y_test) = mnist.load_data()

# reshape data
x_train = x_train.reshape(60000, 784).astype('float32') / 255
x_test = x_test.reshape(10000, 784).astype('float32') / 255

# convert class vectors to binary class martrices
y_train = keras.utils.to_categorical(y_train,num_classes)
y_test = keras.utils.to_categorical(y_test,num_classes)

# build model
model = keras.Sequential()
model.add(layers.Dense(512,activation='relu',input_shape=(784,)))
model.add(layers.Dropout(0.2))
model.add(layers.Dense(512,activation='relu'))
model.add(layers.Dropout(0.2))
model.add(layers.Dense(num_classes,activation='softmax'))

model.summary()

model.compile(loss='categorical_crossentropy',
              optimizer=keras.optimizers.Adam(),
              metrics=['accuracy'])

# fit data
history = model.fit(x_train,y_train,
                    batch_size=batch_size,
                    epochs = epochs,
                    verbose=1)
                    # validation_data=(x_test,y_test))

score = model.evaluate(x_test, y_test, verbose=0,batch_size=1000)

print(score)



